package bean.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;

import entity.User;
import entity.UserSocialNetwork;

@ManagedBean
@SessionScoped
public class UserBean implements Serializable {
	private static final long serialVersionUID = -1626847931067187536L;
	
	private User user;
	
	public UserBean() {
		user = new User();
		
		List<UserSocialNetwork> usns = new ArrayList<UserSocialNetwork>();
		user.setUserSocialNetworks(usns);
	}
	
	public UserBean(User user) {
		this.user = user;
	}

	@NotNull(message = "6 dígitos no mínimo")
	@Size(min = 6, max = 128, message = "6 dígitos no mínimo")
	private String password_2;

	@NotNull(message = "6 dígitos no mínimo")
	@Size(min = 6, max = 128, message = "6 dígitos no mínimo")
	private String password;
	
	@NotNull(message = "6 dígitos no mínimo")
	@Size(min = 6, max = 128, message = "6 dígitos no mínimo")
	private String passwordOld;
	
	@Pattern(regexp="^(http[s]?:\\/\\/)?((w{3}\\.)?)facebook\\.com\\/(?:[^\\s]){5,}$", message="url inválida")
	private String facebook;
	
	@Pattern(regexp="^(http[s]?:\\/\\/)?((w{3}\\.)?)twitter\\.com\\/(?:[^\\s]){5,}$", message="url inválida")
	private String twitter;
	
	@Pattern(regexp="^(http[s]?:\\/\\/)?((w{3}\\.)?)plus.google\\.com\\/(?:[^\\s]){5,}$", message="url inválida")
	private String googlePlus;
	
	@Pattern(regexp="^(https?://)?(([\\w!~*'().&=+$%-]+: )?[\\w!~*'().&=+$%-]+@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([\\w!~*'()-]+\\.)*([\\w^-][\\w-]{0,61})?[\\w]\\.[a-z]{2,6})(:[0-9]{1,4})?((/*)|(/+[\\w!~*'().;?:@&=+$,%#-]+)+/*)$", message="url inválida")
	private String website;
	
	@Pattern(regexp="^(https?://)?(([\\w!~*'().&=+$%-]+: )?[\\w!~*'().&=+$%-]+@)?(([0-9]{1,3}\\.){3}[0-9]{1,3}|([\\w!~*'()-]+\\.)*([\\w^-][\\w-]{0,61})?[\\w]\\.[a-z]{2,6})(:[0-9]{1,4})?((/*)|(/+[\\w!~*'().;?:@&=+$,%#-]+)+/*)$", message="url inválida")
	private String link;
	
	@AssertTrue(message = "senhas diferentes")
	public boolean isPasswordsEquals() {
		return user.getPassword().equals(password_2);
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String getPassword_2() {
		return password_2;
	}

	public void setPassword_2(String password_2) {
		this.password_2 = password_2;
	}

	
	public String getFacebook() {
		return facebook;
	}

	public void setFacebook(String facebook) {
		this.facebook = facebook;
	}

	public String getTwitter() {
		return twitter;
	}

	public void setTwitter(String twitter) {
		this.twitter = twitter;
	}

	public String getGooglePlus() {
		return googlePlus;
	}

	public void setGooglePlus(String googlePlus) {
		this.googlePlus = googlePlus;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	
	
}

